module.exports = function($scope, $modalInstance, $resource, obj, toaster){
	
	$scope.record = obj;

    $scope.load = function(){
		var para = {
			'time': obj.order_state_time
		}
        $resource('/api/as/puc/subsidycount/getMonthSyncList', {}, {}).save(para, function(res){
            if(res.errcode === 0){
				$scope.infolist = res.data;
            } else {
                toaster.error({title: '', body: '获取数据失败'});
            }
        });
	};
	$scope.load();

    $scope.syncData = function(item){
		var para = {
			'time': obj.order_state_time,
			'company_code': item.company_code
		}
		$resource('/api/ac/puc/subsidyCountService/setSyncInfo', {}, {}).save(para, function(res){
			if(res.errcode === 0){
				toaster.success({title: '', body: '成功同步' + res.data.num + '人'});
				item.plan_num = res.data.num;
			} else {
				toaster.error({title: '', body: '失败，请稍后再试'});
			}
		});
	};

	//全部同步
	$scope.syncAll = function(){
		angular.forEach($scope.infolist, function(item){
			if(item.id && item.plan_num == 0){
				$scope.syncData(item);
			}
		})
	};

	$scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };

    
};